<template>
  <section class="component turn-record">
    <data-form :model="queryModel" :page="page" @onSearch="refreshData" ref="form">
      <template slot="inputs">
        <el-form-item label="流转时间起止" prop="turnData">
          <el-date-picker clearable type="daterange" v-model="queryModel.turnData"></el-date-picker>
        </el-form-item>
        <el-form-item label="逾期期数" prop="overduePeriod">
          <el-select clearable placeholder="请选择" v-model="queryModel.overduePeriod">
            <el-option
              :key="index"
              :label="name"
              :value="code.replace(/M|\+/, '')"
              v-for="{ index, name, code } in $dict.getDictData(
                'OverduePeriodStatus'
              )"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="触发动作" prop="triggerAction">
          <el-select v-model="queryModel.triggerAction">
            <el-option
              :key="index"
              :label="name"
              :value="code"
              v-for="{ index, name, code } in $dict.getDictData(
                'TriggerAction'
              )"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="案件类型" prop="caseType">
          <el-select clearable placeholder="请选择" v-model="queryModel.caseType">
            <el-option :key="index" :label="name" :value="code" v-for="{ index, name, code } in $dict.getDictData('CaseType')"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="催收员/受托方" prop="name">
          <el-input clearable placeholder="客户姓名" v-model="queryModel.name"></el-input>
        </el-form-item>
      </template>
    </data-form>
    <data-box :data="dataSet" :page="page">
      <template slot="columns">
        <el-table-column :formatter="row => $filter.dateTimeFormat(row.caseTurnTime)" label="案件流转时间" prop="caseTurnTime"></el-table-column>
        <el-table-column :formatter="
            row => $filter.dictConvert(row.triggerAction, 'TriggerAction')
          " label="触发动作" prop="triggerAction"></el-table-column>
        <el-table-column :formatter="row => $filter.dictConvert(row.caseType, 'CaseType')" label="案件类型" prop="caseType"></el-table-column>
        <el-table-column
          :formatter="
            row =>
              $common.isNotValue(row.overduePeriod)
                ? ''
                : `M${row.overduePeriod}`
          "
          label="逾期期数"
          prop="overduePeriod"
        ></el-table-column>
        <el-table-column label="逾期天数" prop="overdueDays"></el-table-column>
        <el-table-column label="催收员/受托方" prop="name"></el-table-column>
        <el-table-column label="操作员" prop="operatorRealName"></el-table-column>
      </template>
    </data-box>
  </section>
</template>

<script lang="ts">
import { Vue, Component, Prop, Watch } from "vue-property-decorator";
import DataForm from "~/components/common/data-form.vue";
import DataBox from "~/components/common/data-box.vue";
import { Dependencies } from "~/core/decorator";
import { TurnRecordService } from "~/services/domain-service/turn-record.service";
import { PageService } from "~/utils/page.service";

@Component({
  components: {
    DataForm,
    DataBox
  }
})
export default class TurnRecord extends Vue {
  @Prop({ required: true }) private caseNumber: string;
  @Prop() private open: boolean;
  @Dependencies(TurnRecordService) private turnRecordService: TurnRecordService;
  @Dependencies(PageService) private page: PageService;

  private dataSet: any[] = [];
  private queryModel: any = {
    turnData: [],
    triggerAction: "",
    caseType: "",
    overduePeriod: "",
    name: ""
  };

  public query() {
    const dataForm = this.$refs.form as DataForm;
    dataForm.resetForm();
    this.refreshData();
  }

  private refreshData() {
    this.turnRecordService
      .findTurnRecordDetailPage(this.caseNumber, this.queryModel, this.page)
      .subscribe(data => (this.dataSet = data));
  }
}
</script>

<style lang="less" scoped></style>
